package edu.rit.teamrocket.view;

import java.awt.*;

import javax.swing.*;

import edu.rit.teamrocket.model.Food;
import edu.rit.teamrocket.model.FoodCollection;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddFood extends JFrame
{
   private JLabel foodName, calories, fatPercentage, carbPercentage, proteinPercentage;
   private JPanel panel1, panel2, panel3;
   private JTextField nameText, calorieText, fatText, carbText, proteinText;
   private JButton add;
   private FoodCollection foodCollection;
   
   public AddFood()
   {
      super("Add Food");
      foodCollection = new FoodCollection();
      this.setLayout(new GridLayout(0,1, 5, 5));
      foodName = new JLabel("Food Name: ");
      calories = new JLabel("Calories: ");
      fatPercentage = new JLabel("Fat Percentage: ");
      carbPercentage = new JLabel("Carbohydrate Percentage: ");
      proteinPercentage = new JLabel("Protein Percentage: ");
      nameText = new JTextField(10);
      calorieText = new JTextField(10);
      fatText = new JTextField(10);
      carbText = new JTextField(10);
      proteinText = new JTextField(10);
      add = new JButton("Add");
      add.setPreferredSize(new Dimension(5, 5));
      add.addActionListener(new ActionListener() {
 
            @Override
			public void actionPerformed(ActionEvent e)
            {
                Food f = new Food(nameText.getText(), Integer.parseInt(calorieText.getText()),
                		Double.parseDouble(fatText.getText()), 
                		Double.parseDouble(carbText.getText()), 
                		Double.parseDouble(proteinText.getText()));
                foodCollection.getFoods().add(f);
                System.out.println(foodCollection.getFoods());
            }
            });

      
      
      panel1 = new JPanel();
      this.add(panel1, BorderLayout.NORTH);
      panel1.add(foodName);
      panel1.add(nameText);
      panel1.add(calories);
      panel1.add(calorieText);
      panel1.setLayout(new GridLayout(0,1,5,5));
      
      panel2 = new JPanel();
      this.add(panel2, BorderLayout.CENTER);
      panel2.add(fatPercentage);
      panel2.add(fatText);
      panel2.setLayout(new GridLayout(0,1,5,5));
      
      panel3 = new JPanel();
      this.add(panel3, BorderLayout.SOUTH);
      panel3.add(carbPercentage);
      panel3.add(carbText);
      panel3.add(proteinPercentage);
      panel3.add(proteinText);
      panel3.add(add);
      panel3.setLayout(new GridLayout(0,1,5,5));
    
      this.setVisible(true);
      this.pack();
      this.setResizable(false);
    }
}